package com.skymxc.wandroidtodo.page.register;

import android.app.Application;

import androidx.annotation.NonNull;

import com.skymxc.wandroidtodo.R;
import com.skymxc.wandroidtodo.data.net.NetObserver;
import com.skymxc.wandroidtodo.data.pref.PrefUtils;
import com.skymxc.wandroidtodo.entity.UserInfo;
import com.skymxc.wandroidtodo.page.base.BasePresenter;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * <p>
 *
 * </p>
 *
 * @author 孟祥超
 * <p>
 * date: 2021/12/2  9:48 下午
 */
class RegisterPresenter extends BasePresenter<RegisterContact.RegisterView> implements RegisterContact.IRegisterPresenter {
    public RegisterPresenter(Application application) {
        super(application);
    }

    private RegisterModel registerModel = new RegisterModel();
    @Override
    public void register(String username, String password, String repassword) {
        view.showProgress(application.getString(R.string.registering));
        registerModel.register(username,password,repassword)
                .subscribe(new NetObserver<UserInfo>(compositeDisposable,view) {
                    @Override
                    public void onNext(@NonNull UserInfo userInfo) {
                        PrefUtils.saveUserInfo(userInfo);
                        view.registerSuccess();
                    }
                });
    }
}
